class Solution:
    def addBinary(self, a: str, b: str) -> str:
        ans, carry = '', 0
        for i in range(max(len(a), len(b))):
            n1 = int(a[-i - 1]) if len(a) - 1 - i >= 0 else 0
            n2 = int(b[-i - 1]) if len(b) - 1 - i >= 0 else 0
            sumVal = n1 + n2 + carry
            ans = str(sumVal % 2) + ans
            carry = sumVal >> 1
        if carry:
            ans = str(carry) + ans
        return ans
